fix bugs & optimize