Reimplement bitstream

Looks like another bunch of awesome changes! Let me know when it's ready for merge..