Some refactoring of code