Fix bugs and syntax