Advanced theory of waveguides