i'm not sure how getValue() is supposed to be called, but I would make it work correctly even if it is called twice.  that is, set cx back to zero after you accumulate.