restructure, optimizations by shay #1

-> use register for events