Refactored server code for better readability.