Fix bug in wrapping and unwrapping functions.