Beginning of database helper functions.