implemented swapping
final merge