Improved check to prevent php notice