Fixed case where script would get stuck