Memory usage improvements

various changes to reduce memory usage in BRJS.