Fix memory issues