bug fixes and type tweaks