added better handling of exceptions, stub'd out console.log and console.error