Added error handling and test program.