fixed some memory usage issues.