Added some logic to login, refactored server while at it