refactored cloud code