refactored and optimized _.isEqual