More pythonic file handling, and some fixes.