fixed bugs and added additional error handling, and test data