Refactor, add unit test and travis