Refactor

Making a start on some tidying up, sticking it in here for now (cc: @prust).