Fix a couple of bugs with configuration, clean up code a little bit