Pythonizing code and writing comments on some code pieces