move layout into a function