Various tweaks and bug fixes