refactoring : put some common code in methods