refactored view layout code