refactor to use call_command() and CommandIO (thanks @hodgestar)