Made some effort at reducing memory use. Implemented #54