Added ref case, refactored closure conversion code