Replacing hasAttribute with try/catch.

Also added todo about performance issues in previous commit