private String updateAccountBalance(String residentId, double amount, Session session, boolean isCredit) {
        Double cashBackPercentage = Double.parseDouble(env.getProperty("cashback_percentage"));
        Transaction tx = session.getTransaction();
        String hql = HibernateQueries.getAccountsQueryBasedonResidentId(residentId);
        System.out.println("\n\n\n\n The query string is :::" + hql);
        org.hibernate.Query query = session.createQuery(hql);
        List<Account> results = query.list();

        Account userAccount = null;
        JSONObject response = new JSONObject();
        if (isCredit == true) {
            if (results == null || !results.isEmpty()) {
                userAccount = results.get(0);
                double currentBalance = userAccount.getAmount();
                userAccount.setAmount(currentBalance+amount);
            }
            else {
                userAccount = new Account(residentId,amount,0,0);
            }
            response.put("Current Account Balance",userAccount.getAmount());
            response.put("Success","Credited account with "+amount);
        }
        else {
            if (results == null || !results.isEmpty()) {
                userAccount = results.get(0);
                double currentBalance = userAccount.getAmount();
                double currentBonusBitcoins = userAccount.getBonusBitcoins();
                if (currentBalance < Math.abs(amount)) {
                    response.put("Error","Not Enough Balance in Account");
                    response.put("Current Account Balance", currentBalance);
                    return response.toJSONString();
                }
                double bonusBitcoins = Math.abs(amount*cashBackPercentage);
                userAccount.setBonusBitcoins(currentBonusBitcoins+bonusBitcoins);
                userAccount.setAmount(currentBalance + amount + bonusBitcoins);
                response.put("Current Account Balance",userAccount.getAmount());
                response.put("Success","Debited account with "+ -amount);
            }
            else {
                response = new JSONObject();
                response.put("Error","Account does not exist, please credit the account with some bitcoins before debit");
                return response.toJSONString();
            }
        }

        try {
            tx = session.getTransaction();
            session.save(userAccount);
            tx.commit();
        }
        catch(HibernateException e) {
            if (tx!=null) tx.rollback();
            e.printStackTrace();
        }

        if (response == null) {
            response.put("Error", "Unable to process your request");
        }
        return response.toJSONString();
    }