This to me begs for it's own function, called from here