refactored code on layout