adding documentation, fixing some bugs