Adding unit tests and fixing bitstream code. Ready for networking API.