added versions of trish-inspired mr and hist that deal slightly better with degenerate cases and have partially unrolled loop