bug fix and add log function