Add onready and onstatechange event handlers