Added logic for operator precedence