Fixed the wrapping algorithm