Fixed bug and improved legend