clarify code, add comments, cleanup.