various level optimizations (faster init/undo, fixed memory leaks)