Cleaned up db code

Moving all db calls into abstractable interface