Python 3 support and PEP8 fixes

Added Python 3 support, directory existence checking and some PEP8 fixes.