Refactored code for web service functions