Start refactor of encoding to handle reference set