design, code flow, comments

updated design
fixed flow
added comments