JS refactoring that fixes presence errors in earlier reverted commit.