Can't understand my spaghetti code.