Fixed next function being called even though it's finished.