fixes buffer underflow due to signedness error