exchanged some sprintf with snprintf