Prevented commands being run midway through a generator.
Added close() function for use when you want to explicitly close
a connection (perhaps parts way through a generator)
Tidied up a bit.