Completed the database functions