Use std::next and std::prev for cleaner code