added documentation, fixed some bugs