Refactor. Use latest stuff from cloudly.