made the fix more generic and robust