Refactoring of some common code