replace sprintf with snprintf