add comments, remove old code, improve formatting