Some code sorting, and added check for sm2 object to be loaded before including some modifications in order to avoid breaking the js [#681474] by electblake