slight refactor; add documentation
reformat code