Fix grouping and literal optimization