Added some extra JS validation.

Added some error codes and comments.