Unit test bug fixes and etl refactoring