various memleak fixes