some fixes to improve memory usage