Refactor a little more, and update to JS API 3.5.