 				raw = raw+""
 				percent = +(raw.substring(0, raw.length-1))
 			amount = Math.round((remainder*100.0)/totalShare*percent)/100.0
-			Db.shared.modify 'balances', userId, (v) -> 
+			old = Db.shared.peek('balances', userId)
+			newValue = Db.shared.modify 'balances', userId, (v) -> 
 				#log "v="+v
-				result = (v||0) + amount
+				return (v||0) + amount
 				#log "result="+result+", parsed="+parseFloat(result)+", amount="+amount+", v="+v
-				return parseFloat(result)
 			lateRemainder -= amount
+			log "userId="+userId+", total="+total+", old="+old+", balance+="+amount+", new="+newValue
 			#log "amount="+amount+", remainder="+remainder+", totalShare="+totalShare+", percent="+percent+", lateRemainder="+lateRemainder
 		#log "lateRemainder="+lateRemainder
 		if lateRemainder isnt 0  # There is something left (probably because of rounding)

				remainder -= amount
			if (total < 0)
				number = -number
			Db.shared.modify 'balances', userId, (v) -> 
				result = (v||0) + number
				return parseFloat(result)
	#log "total="+total+", totalShare="+totalShare+", remainder="+remainder	
	if remainder isnt 0 and divide.length > 0
		lateRemainder = remainder


# Process a transaction and update balances
balanceAmong = (total, users, txId = 99) !->
	log "balanceAmong: total="+total+", users="+JSON.stringify(users)+", txId="+txId
	divide = []
	remainder = total
	totalShare = 0
