event based rewrite

small core with everything going through events
its already fixed in master, this is outdated