Added error reporting, not tested yet