refactored codes except loan:set_for_ci()