fix many issues & optimize