reinstated logic from original clean script which is no longer called