Rewrote codec implementation, still not complete