factored out JavaScript