restructured the code. marked function groups. more descriptions.