added log() method, refactored