added documentation, some renaming of varnames