Split misc.py into separate files in tools subdirectory (update of pull request #382)

As discussed in the previous pull request (#382), I have split misc.py into multiple files in the directory tools, and kept misc.py just as a wrapper.  This reduces the size of imports, makes the files smaller and easier to read, avoids circular dependencies, and should make debugging easier.