fix a few memory issues