further cleaning up

mostly type-guided (and thus guaranteed safe) refactoring