Code cleanup and bug fixes

addresses https://github.com/OpenBazaar/OpenBazaar/issues/282 https://github.com/OpenBazaar/OpenBazaar/issues/322 and a few similar issues
Thanks for the review. I will add a test in our build to check for `\n` at EOF.