fixed some bugs and added some doc
added doc and cleaned up a bit of stuff