Refactor settings handling.