Updated swapRows method to work with dictionary instead of list