correcting some memory miss management and leaks. Adding the object pool pattern, as a template