Update server api
Refactor and cleanup code