handle wrap around

Change-Id: I0d9ff505111691d4aac07e7a3651d1b7fc844c9b