fixed logical issue and typo