Fixes memory problems