adding error handling and tests