Refactored some cloud JS