Bug fixes  related to memory usage