Refactored the command running/parsing code to be more concise.