Change for to foreach.
Add command and window parameter.