Add tests and fix a 16bit vs 32bit integer bug

Yay unit tests!