fix bugs, remove unused lines