moved bulk of view code to layout