Performance optimization (problem with grammar in expressions)