Add comments, improve code flow