Added vars support, docs, comments, and rewrite the rest