fix outofbound exception on swap