refactor tests for better error checking