cleaned up up/down code so rows are found only once