More robust version (doesn't crash when called from aliroot)