Fixed infinite loop bug on last click