moved all layout logic to layouts.js