Finished most of the database functions