Improve flood algorithm