Added hasattr check for backward compatibility.