add pool threads, fix bugs, full refactoring