rewrite, courtesy of dustin