reduced code in 1 function