Refactored functions module