add logger and refactor