commented code and optimizations