fixed those weird infinite loop bugs