Added scale legend

and some bug fixes