refactor the command code