Improve code

Remove some unused code and some duplicated code. Rework how test settings are handled.