UPDATED working on an error object instead of just returning null and logging. Not completed.