refactored code layout