added some setting and refactoring for speeding up