login function and minor fixes