Small fix, make reachedEnd a global var.