refactoring API calls, validation and db creation