Fixed legend detection bug