Theory of waveguides