added documention and tweaking