Check `ret_val` instead of `i`
Stop trying to factor using `ecm` when `n` is a probable prime