Refactor clearResults() function into a service function