Added reference error handling