added better comments and put a summary at the top