Reorganized flowchart code, added some comments.