change to logging and remove useless while