Misc bug fix and enhancement