SQL tweaks and allow limiting groups