refactoring and add PerfTests