move layout call outside of loop