Add some error checking before doing work.