Refactor cloud code.

Move some parts to CloudConfig and CloudUtility.
This will make the structure clear.