Fixed memory issues