this all needs thorough rethinking.