Fix #159 - ensure the object exists before accessing