moving logging to a separate function