refactored the api and database, along with other cleanup