added automatic document refreash on entering foreground