Some minor fixes so there is no infinite loop