fix double free bug which cause error handling fail and add '%' support