changed database functions to make more sense