Refactors server to create server instances and adds tests for serve method