Refactor javascript closes #12