Change checks for undefined to check variable type instead of value to prevent errors