fix bugs & improve codes