Issues #25,#26,#27. Rewrite script in Python.

Please test this at least on Ubuntu and Windows.