Fixed and optimized floodfill