logging abstracted to a new function to avoid repeating