closes #30

also includes performance enhancements for loops