Remove duplicate code in one class