Memory issue fixes