memory leaks corrected