Documenation and clean up

External documentation in markdown files. Started documentation in code.
Also cleaned up some stuff.