Fixed issue, but has a memory leak