Moved code to DB access layer