Cleans-up imports and fixes mock patching in tests.