added error handling (more tests need to be done)