Adding docs and rearranging code for clarity. Also added more specific TODO's.