Fixed logging and cleaned up imports
Reformatted as per PEP8. Added docstrings