Now rerendering function works fine