cleans up code for jslint and adds event unbinding.