simplified inner algorithm use closures embbeded in events instead of switch-case.