this is essentially the only change. extracted a method to make testing easier