Swapped all sprintf's for snprintf, and strcpy for strncpy. Also removed console printing for speed and less resource consumption.