allow the user to choose the refresh interval ; improve script structure