Fix bugs and some other changes