Fix JS function calling bug, closes #4