Fixed nearly all code; todo in code and SourceNotes.txt