Fix sweeping algorithm