Replace branch constructs with appropriate get and setdefault calls; remove unnecessary get calls