reducing memory usage and other minor fixes