Fix bugs introduced in last JS refactor