Refactor configuration. Closes #2203