Moving setcancelled to above conditionals in case they error.