updated logic for wrap backwards