Fixed refresh() so it dose not crash the program