Rewriting when clausule for not use in main