Patches from James H. The usual stuff (memory leak fixes and 16-bit