Refactored the utility functions