Three-dimensional nonlinear theory of the free electron laser