Rearrange the code a bit. Add a config class.