bug fix and remove redundant code