code clean-up and documentation