rewriting calculator -> event driven