duplicated. can be moved outside "if then else"