update
Stable version with partial optimization