Fix #294.

Fix #294 and a related issue. (Need to check for element existence instead of comparing it)