add comments and do light restructuring