some tweaks to make it work more reliably