optimise the database calls