Fixes Bug #497 and Partial Fix for #390

This commit fixes #497, using an Object.prototype.valueOf comparison.

Partial fix for #390