more robust version