addevent, reworked some of the code