changed out region search algorithm not to use recursion