Refactoring: moved database functions to seperate class