Cleaned up database code