Quello che scrivi è insufficiente per capire ciò che succede, prova apostare tutto il codice funzionante.