some refactor work on chargen