Fix some memory issues