fix horrible logic bug