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