refactored as_typed_vector for efficiency, improved its error messages, and refactored colourising