tweaks and several bug fixes