Fix bugs and errors

Fix bugs and errors