Code cleanup and some small fixes.
Added encoder stream.