Refactored server code to classes.