Bunch of test tweaks and code improvements