Correction of the code. Adding swap() method.