fixed bugs and added a ton more documentation