Implement recursion for runcommand