moving functionality to one function