working version on VF - 30 minutes for whole dataset