layout code refactoring, step 2