fixed over/underflow issues