Added some documentation and removed dead code