fix wrap around problem