Added the beginning documentation and fixed a few bugs.