Clean and refactor various tests and sources.