Various tweaks and code cleanup