Refactor ViewUtils

Improved type safety and reduced complexity.