Tweaks to checks to patch flaws, as well as code overhaul