Cleaner implementation. Use external encoder classes.