Add undefined checks