Updated lots of code to use nio.2. Fixed a few bugs.