Minor bug fixes and style improvements

I've made a few bug fixes and style improvements:

 * The bugs involved java.lang.String objects being compared with == when they should be using String.equals
 * Make the client implement the Closeable interface to make it easier to use with Java 7 try-with-resources
 * A bunch of very minor style improvements