Respond to nikb's changes, and remove more duplicate code.