JavaScript bug fixes

This patch addresses issue #39, #38, #36, #34. 

There is also one C89 (#29) fix, but I think there are others that still need to be done.