Fixed errors, enhanced event handlers