Several tweaks to improve performance and reduce unnecessary tests