Existing code with memory leak fixed and better constructors