Optimize ONERROR code