added error handling, basic tests