Complete optimized version not parallel