Move command processing to separate functions