Added check for returned error when executing queries.

Also fixed unit test error.