Fast inhomogeneous plane wave algorithm for multi-layered medium problems