Some refactoring and encoding stuff.