Code clean-up and documentation