Made delatching levels adaptive and fixed memory issue.