Refactored a bit in preparation for adding cloud view.