refactored sca to use shared utilities and be more testable

While I added more tests for the ``sca`` module, the changes have partly been quite substantial, so an integration test by running a complete real-world workflow using ``sca`` would be good.