Fix logic and typos