Made the db access more dynamic