slight code rejigger