Optimizations and fixes for identifier terms