Write queue issue, memleak fix