adding QPool with some refactoring