refactoring methods and add some new features