fix some leaks
handling errors a little better...