Fixing refresh issue. Still not complete and needs more testing.