fixed some bugs and added documentation