Refactoring server into lib.