Some refactoring and modifications.