Fixed some bugs & leaks
Minor changes needed for nVm commit : fd37abdc849ec0201f0f8340d0d257df2dc4663d