Refactored server to be cleaner and use dependency injection.