refactoried code