Improving logic of last row