Cleaned up code and added some new config options.