code clean-up and doc