Fixed crashes and use std::swap.