code cleanup. added inline comments.