Moved DB related fn to seperate module