Major refactor to contain public JS API