Fixed memory errors