code cleanup and login fix