Logic and typo fix