A bit of a mess, but refactor in progress