Working but with memory leak