refactored shared functions between controllers into services