Stuck with program flow and freezing programm