refactored loan api