Updated flood fill algorithm with stack.