Re-structure code to provide a simple in-page js API.