Flip legend order; fix bugs described in #97