Optimized the serial version