added comments and Pythonicized