change loop structure so that the server won't timeout.