fixed a few runtime errors and added more documentation