refactor when/then to let we can add action for then