refactored spaghetti db calls