more tweaks and code cleanup