add docs and move stuff around for readability