further cleaning up

mostly type-guided (guaranteed safe) refactoring