Added docs, multiple refactors.