various bug fixes and changes