Fixed initialization bugs and error reporting