Fix JS loading bugs