Moved $command outside of loop