Refactor to_int