Login issues fixed, cleaning up code