using now reentrant versions of localtime and strtok; cleaned up logging in JS