Tidied up the command code a bit & added some docblocks