refactoring (remove duplicated code)