Do some refactoring and tiny changes.