Move OnError to the right place