made some changes to speed up...1362ms for 1024*1024 with 8 cores with pcg off