public synchronized void addStock(String uid, Float decrement, HashMap<String, Integer> stocks) throws IOException {
        try {
            Node userNode = getUserNode(uid);

            NamedNodeMap attr = userNode.getAttributes();
            Node nodeAttr = attr.getNamedItem("balance");

            Double newamount = Double.parseDouble(nodeAttr.getTextContent()) - decrement;
            nodeAttr.setTextContent(newamount.toString());

            while (userNode.hasChildNodes()) {
                userNode.removeChild(userNode.getFirstChild());
            }

            Iterator it = stocks.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry) it.next();
                System.out.println(pairs.getKey() + " = " + pairs.getValue());
                //it.remove(); // avoids a ConcurrentModificationException
                Element newStock = doc.createElement("stock");
                newStock.setAttribute("identifier", pairs.getKey().toString());
                newStock.setAttribute("quantity", pairs.getValue().toString());
                userNode.appendChild((Node) newStock);
            }

            commitFile();

        } catch (Exception e) {
            System.out.println("Error in updating");
        }
    }