Added more documentation and fixed bugs.