change all the sprintf to snprintf to address the potential buffer/stack overflow