Refactored the api server to be more modular