small fixes, and detect a memory leak

the full fix for the memory leak is to come in another commit