Refactored code for layout