Added more documentation and fixed a few bugs