Refactored some utility methods into extension methods