Refactored database calls to another function. TODO(PS): More refactoring needed for the queries. Lots of repititive code present