Fix bugs and errors