modularised the database calls