Fix some memory errors