fix an old bug and newly introduced ones