Use the same mode setting throughout
Add some helpful comments
Optimize test code using a loop