more documentation and fixing some bugs I found in the head.