Tidy up a bit. Minor bug fixes