Trying to correct unexpected program crash