added documentation and clean-up