Added bidirectional judging