added some error handling, added start of unit tests