scan first algorithm.