Moved DB functions to separate module