Fixed handling of |onclose|