added some error handling
added test case (probably defunct)