several minor bug fixes and enhancement