Fix logic error in TP detection