code to reduce memory errors