Typescript / JS bug fixes. Fully working JS implementation now!