added error handling and basic test framework