Patches to fix s3n:// filesytem quirks.

PTAL @etorreborre thanks. By the way I tried running the tests and keep getting the following message:
Internal error when running tests: `java.lang.OutOfMemoryError: PermGen space`

This is even after setting the flags: `SBT_OPTS=-Xms2048M -Xmx4096M -XX:MaxPermSize=2048m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled`
Completely agree that I made the logic difficult to read. I will take a stab at cleaning it up, will submit a new PR shortly...