fix bug that required a refresh of the page sometimes