memory optimizations for issue #373