added documentation and optimizations to test file