Refactors several things and properly fixes the login mechanism