Settings: Refactor code to make it cleaner.

Also got the tests working again.