fixing memory errors