Added function that takes an err object