changed flood fill function to prevent stack overflow crashes