fixes missing error checks and bad database calls
adds tests for missing error checks