added error handeling
Added ability to add global data (via $ij)