plumbing for pure js implementation
cleaned up JS