Refactoring and add some new features