added log, refactoring