Removing textWidth var and adding it to gap for showLegend
Added some simple text wrapping logic for long legends
Changing space iterator to use z instead of i