adding comments, renaming some main loop vars etc for easier code tracking and modifications