Refactoring some common code