fixed some dumb bugs
added documentation and made refinements