added safety checks