Refactored error, security, and user service for readability