Rewrote the database functions to apply the schema. Also rewrote many of the select queries and auth logic.