private synchronized void handleLimitOrders() {

		List<MarketOrder> limitBuys = dao.getLimitBuys();
		List<MarketOrder> limitSells = dao.getLimitSells();
		Metadata metadata = metadataDao.findAll().get(0);

		if (limitBuys.size() > 0 && limitSells.size() > 0) {
			for (int buyCt = 0; buyCt < limitBuys.size(); buyCt++) {
				int price = limitBuys.get(buyCt).getPrice();
				int buyAmount = limitBuys.get(buyCt).getAmount();
				for (int sellCt = 0; sellCt < limitBuys.size(); sellCt++) {
					if (price == limitSells.get(sellCt).getPrice()) {
						long time = new Date().getTime();
						MarketOrder limitSell = limitSells.get(sellCt);
						MarketOrder limitBuy = limitBuys.get(buyCt);
						int sellAmount = limitSell.getAmount();
						int smallerAmount;
						if (buyAmount > sellAmount)
							smallerAmount = sellAmount;
						else
							smallerAmount = buyAmount;
						limitBuy.fulfillOrder(smallerAmount);
						limitSell.fulfillOrder(smallerAmount);
						dao.merge(limitBuy);
						dao.merge(limitSell);
						
						Client buyClient = clientDao.findById(limitBuy.getClient());
						Client sellClient = clientDao.findById(limitSell.getClient());
						buyClient.buyShares(smallerAmount, price * smallerAmount);
						sellClient.sellShares(smallerAmount, price * smallerAmount);
						clientDao.merge(buyClient);
						clientDao.merge(sellClient);
						
						Sale sale = new Sale(limitBuy.getClient(),
								limitSell.getClient(), smallerAmount, price, time,
								limitBuy.getId(), limitSell.getId());
						saleDao.persist(sale);
						
						metadata.addToVolume(smallerAmount);
						if (metadata.getHigh() < price) metadata.setHigh(price);
						if (metadata.getLow() > price) metadata.setLow(price);
						metadata.setLast(price);
						metadataDao.merge(metadata);
					}

				}
			}
		}
	}