Add documentation and remove some unused code