Tweaked code base so it can encode to either a stacked based array or dynamically allocate an array.