wrapping logics in seperate function