Refactor settings and add test infrastructure
Tests for settings and minor refactorings