Added code and fixed a few doc bugs