Fixed a bug when offset was negative.