Mode management in main encoding function
Merge remote-tracking branch 'origin'
Removed duplicate intermediate buffer