make code nicer and add server down checker