Refactor configuration handling