added comments, and some looping logic for preliminaries.