Improve cave scanner algorithm