Add defensive codes for weird situations that have yet to appear