refactor code a little; add tiny bit of docs