fixed 32 bit rounding bug and moved encoding around