Implemented swap subroutine