abstract, cleanup and document

Separate the methods that actually insert dom element for easier
testing.

Cleanup, and order methods more logically

add "docstring"