Created functions to query the database