tidying up, minor leaks fixed