refactoried the code

fixed #10