added flowchart and finalized code