using green matrix instead of double loop.

result is unchanged