bug fix and code improvement from code review