Fix sequence handling bugs