Memory leak fixed and old code removed