Fix bug in flood algorithm