add unittest
refactoring