Further amendments to login function.