added legend + better handle response code