Refactor onCommandPreprocess()