Various tweaks and code improvements