Refactor server to be testable