Added rewrite rules to optimize for loops.  Fixes #28