commented and optimized