Strip out some redundant code and do a bit of housekeeping.