Fix appendBits

According to some quick math, this would have affected input sizes above 10^17 decimal digits.
Refactor appendBits
Add test for appendBits
Fix/clarify comments