refactored the processing of rows, still trying to fix the random shape deletion :(