use std::swap instead of hand coding