added tolerance for events + too many other changes
cleaned code and API