Refactored the base function