fix if -> when change
remove dependency cycle
fix tests