change error handling and add integration test for cycle