add some type-hints, and fix terminated reduction