A bit nicer way to fix the head inf loop problem.