finalized code, comments, and flowchart