refactored the code layout