move database check into seperate function