removing duplicated logic