javascript made more robust to prevent strange errors
It works!!! for real this time, I think.