used function reduced 60% of code
added a function and reduced code again