cleaned up code, added struct docs

cleaned up code, added struct docs, rearranged some items for readability.