Moved logging to a dedicated function