refactored get rows method