Can we write this slightly more functionally? Declare a val for this

    val index = if (b < 0) b + 256 else b
    uniques(index)

I am not sure if the IndexOutOfBoundsException exception is necessary, since accessing an array with an invalid index will throw a similar exception already.