First cut of semi-working functionality. To be tidied