Better implementation for scanning.