Fix bug and improve if ~ else.