combine the error checking below