refactoring modules-move database functions to models