Some refactoring of code.