Stable version, now trying to optimize memory usage