Changed log procedure and refactoring