refactored code strucuture