Rewritten how commands are managed and added commenting to make things
easier to follow.