moved database queries into API functions