various bug fixes and enhancement