Fixing Memory Management Issues