Refactor onCommand

The onCommand Function had a lot of duplicated code segments and extra if/else checks that hampered its' readability. Fixed by factoring out the most common checks, deleting copypasta, and utilizing a switch statement. .