Text this: Flexible Least Squares Algorithm for Switching Models