Refactoring of some code