moving code to layout