refactored server error handling to separate function
added function to find user by id
controller for handling user session