with dictionaries

Also simplified replacement