add some logging
fix the `having` clause