cleaned up (refactored) commandHandler, it's now much easier to read and
expand in the future.