refactor Ret op from 3 into 1 function