Abstract database functions to separate class