Optimize classes comparison