fix overflow and transition bug