Split misc.py into separate files

As we discussed, I have split misc.py into multiple files.  I have tried to keep functions that are related both in terms of purpose and dependencies together.