moved logging into its own function