some fixes, optimized memory usage