refactor the log code