Preventing memory leak