Fixed bug in swapping rows in energy matrix.