Completed First Version of round-switching algorithm