refactored display layout logic