major refactor, separated the REST and DB APIs