added new commands; tidied up code