refactor and add new log function