added credit calc function