Partially fixed branch for js back end
it breaks on test case 43, but seems to work for the most part.
Further testing needed, but wanted to commit this fix first