Fix some bugs and remove unused files