moved logging in seperate function

as it doesn't clutter with normal flow