Added a onPreClose() callback