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
Need \n at EOF.