added log function and corrected variable naming