Simplifying the test_extraction code and a few clean ups