added exceptions to database, cleaned up queries