rewrite. see my comments for 2_5 solution