fix bugs and errors