Changed STRCAT for SNPRINTF and fixed a few bugs. The main thread still
seems to be exiting.