Fixed wrap-around bug