debug fix, speed fix and refactoring