refactorig and add example