Refactored gather_rows method