Fixed onopen and added some comments