Rewrite command handling for more flexibility.