fix bugs, improve performance