javascript factored out