optimized by using groupshared memory