optimizations, plugged  memory leaks