Now includes settings

Two text fields and a checkbox. Lots of other cleanup too. Trying to
use early variable definitions to simplify.