Refactor/separate database from service layer