not interestring memleak fix and minor refactoring