refactor the code about periodic click