some more refactoring, still not able to solve the problem with tre tree parsing (malloc) in OSX