In Javascript, ^ does xor, not exponentiation.  Fix some bugs that
made this mistake.