Simplified using typed funcs somewhat.