Refactor and fix getNumberOfLoans