Finally removed select_ws and did some more tidying. The code is much nicer now and has less calls to needless functions.