Fix deprecation and memory related issue.