cleaned up logging function