Merge pull request #180 from NextThought/master

Close various files when finished writing to them; fixes ResourceWarnings and some PyPy uses.