Some code clean-up and documentation