Refactored some code in get applications API call