refactored to use cursor / single fetch instead all at once