objectified code, added legends and legend items