Some fixes for HAVING according to Paul's review