Code clean-up and full diagram added