optimizations

huge efficiency boosts and memory leak resolved