changed localhost to SERVER[HTTP_HOST], fixed bugs