fixed wrong script logic