Fixes JS error

@DFurnes wrote all of this and I should deserve no credit for this commit