refactoring the general encode commands one level up.