simplify and make nested commands work properly