changed sprintf to more secure snprintf to prevent vulnerability to buffer