checking that variables exist before using them