Refactor view layout code to match latest version