Add some defensive error checking code
Add some test code