bug fix and improve performance