more or less understand this code now, but am not completely comfortable with the xBalance and the testing techniques