Refactored the code a bit and made login mode