Updated to work with non-pretty URLs