Fixed a bug and replaced snprintf with std::to_string