implemented SCAN algorithm