try to pythonise code