refactored, now need to assess performance